package com.mantou.mantouaiagent.rag.ragadvisor;

import com.mantou.mantouaiagent.rag.queryAugmenter.GeneralContextQueryAugmenterFactory;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.ai.rag.retrieval.search.DocumentRetriever;
import org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.stereotype.Component;

/**
 * @author mantou 构建自定义通用rag增强顾问工厂
 */
public class GeneralRagCustomAdvisorFactory {

    public static Advisor createGeneralRagCustomAdvisorByType(VectorStore vectorStore,String type)
    {
        DocumentRetriever documentRetriever = VectorStoreDocumentRetriever.builder()
                .vectorStore(vectorStore)
                .topK(5)
                .similarityThreshold(0.5)
//                .filterExpression() 需要过滤条件 可以动态添加 .advisors(a -> a.param(VectorStoreDocumentRetriever.FILTER_EXPRESSION, "type == 'Spring'"))
                .build();

        return RetrievalAugmentationAdvisor.builder()
                .documentRetriever(documentRetriever)
                .queryAugmenter(GeneralContextQueryAugmenterFactory.createInstanceFalse(type))
                .build();
    }

    public static Advisor createGeneralRagCustomAdvisor(VectorStore vectorStore)
    {
        DocumentRetriever documentRetriever = VectorStoreDocumentRetriever.builder()
                .vectorStore(vectorStore)
                .topK(3)
                .similarityThreshold(0.8)
//                .filterExpression() 需要过滤条件 可以动态添加 .advisors(a -> a.param(VectorStoreDocumentRetriever.FILTER_EXPRESSION, "type == 'Spring'"))
                .build();

        return RetrievalAugmentationAdvisor.builder()
                .documentRetriever(documentRetriever)
                .queryAugmenter(GeneralContextQueryAugmenterFactory.createInstanceTrue())
                .build();
    }
}
